import {get, post} from "../../utils/req";
import {alert} from "../../components/common/alert";

const empty = {total: 0, list: [], page: 1, size: 10};

export async function list(data) {
    try {
        return await post('/private/order/list', data) || empty;
    } catch (e) {
        alert(`获取订单信息失败：${e}`, 'error');
        return empty;
    }
}

export async function save(data) {
    try {
        return await post('/private/order/save', data);
    } catch (e) {
        alert(`保存订单信息失败：${e}`, 'error');
        return 0;
    }
}

export async function status(id, type, status) {
    try {
        await get(`/private/order/status?id=${id}&type=${type}&status=${status}`);
        return true;
    } catch (e) {
        alert(`更新订单状态失败：${e}`, 'error');
        return false;
    }
}

export async function paid(id) {
    try {
        await get(`/private/order/paid?id=${id}`);
        return true;
    } catch (e) {
        alert(`更新订单状态失败：${e}`, 'error');
        return false;
    }
}
